/**
 * @fileoverview Blocks template for modification.
 *
 * @license Copyright 2017 The Coding with Chrome Authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * @author mbordihn@google.com (Markus Bordihn)
 */
{namespace cwc.soy.Blocks autoescape="strict"}


/**
 * Blockly file blocks.
 */
{template .files}
  {@param files: ?}

  <category name="{msg desc="File Blocks"}Files{/msg}" colour="150">
    {foreach $file in keys($files)}
      {switch $files[$file]['media_type']}
        {case 'audio'}
          <block type="general_file_library_audio">
            <field name="filename">"{$file}"</field>
          </block>
        {case 'image'}
          <block type="general_file_library_image">
            <field name="filename">"{$file}"</field>
            <field name="preview">{$files[$file]['content']}</field>
          </block>
        {case 'text'}
          <block type="general_file_library_text">
            <field name="filename">"{$file}"</field>
          </block>
        {default}
          <block type="general_file_library">
            <field name="filename">"{$file}"</field>
          </block>
      {/switch}
    {/foreach}
  </category>
{/template}


/**
 * Blockly default blocks.
 */
{template .defaultBlocks}
  {call .defaultBlocks_ /}
  {call .defaultColorBlocks_ /}
{/template}


/**
 * Blockly blocks without colors.
 */
{template .defaultBlocksWithoutColors}
  {call .defaultBlocks_ /}
{/template}


/**
 * Blockly advanced blocks.
 */
{template .defaultAdvancedBlocks}
  <category name="{msg desc="Logic Blocks"}Variables{/msg}" custom="VARIABLE" colour="330"></category>
  <category name="{msg desc="Logic Blocks"}Functions{/msg}" custom="PROCEDURE" colour="330"></category>
{/template}


/**
 * Blockly default display blocks.
 */
{template .defaultMessengerBlocks}
  <category name="{msg desc=""}@@BLOCKS__CONTROL{/msg}" colour="120">
    <block type="general_messenger_delay">
      <value name="time">
        <block type="math_number">
          <field name="NUM">5</field>
        </block>
      </value>
    </block>
  </category>

  <category name="{msg desc=""}@@BLOCKS__DISPLAY{/msg}" colour="120">
    <block type="general_messenger_display_text">
      <value name="text">
        <block type="text">
          <field name="TEXT">Hello World</field>
        </block>
      </value>
    </block>

    <block type="controls_for">
      <field name="VAR">countdown</field>
      <value name="FROM">
        <block type="math_number">
          <field name="NUM">10</field>
        </block>
      </value>
      <value name="TO">
        <block type="math_number">
          <field name="NUM">1</field>
        </block>
      </value>
      <value name="BY">
        <block type="math_number">
          <field name="NUM">1</field>
        </block>
      </value>
      <statement name="DO">
        <block type="general_messenger_display_text">
          <value name="text">
            <block type="variables_get">
              <field name="VAR">countdown</field>
            </block>
          </value>
        </block>
      </statement>
      <next>
        <block type="general_messenger_display_text">
          <value name="text">
            <block type="text">
              <field name="TEXT">Go</field>
            </block>
          </value>
        </block>
      </next>
    </block>

    <block type="general_messenger_display_clear">
    </block>

  </category>
{/template}


/**
 * Blockly default blocks.
 */
{template .defaultBlocks_ private="true"}
  <category name="{msg desc="Logic Blocks"}Logic{/msg}" colour="210">
    <block type="controls_if"></block>
    <block type="logic_compare"></block>
    <block type="logic_operation"></block>
    <block type="logic_negate"></block>
    <block type="logic_boolean"></block>
    <block type="logic_null"></block>
    <block type="logic_ternary"></block>
  </category>

  <category name="{msg desc="Loops Blocks"}Loops{/msg}" colour="120">
    <block type="controls_repeat_ext">
      <value name="TIMES">
        <block type="math_number"><field name="NUM">10</field></block>
      </value>
    </block>
    <block type="general_infinity_loop"></block>
    <block type="controls_for">
      <value name="FROM">
        <block type="math_number"><field name="NUM">1</field></block>
      </value>
      <value name="TO">
        <block type="math_number"><field name="NUM">10</field></block>
      </value><value name="BY">
        <block type="math_number"><field name="NUM">1</field></block>
      </value>
    </block>
    <block type="controls_forEach"></block>
    <block type="controls_flow_statements"></block>
    <block type="controls_whileUntil"></block>
  </category>

  <category name="{msg desc="Math Blocks"}Math{/msg}" colour="230">
    <block type="math_number"></block>
    <block type="general_input_angle"></block>
    <block type="math_arithmetic">
      <value name="A">
        <shadow type="math_number">
          <field name="NUM">1</field>
        </shadow>
      </value>
      <value name="B">
        <shadow type="math_number">
          <field name="NUM">1</field>
        </shadow>
      </value>
    </block>
    <block type="math_single">
      <value name="NUM">
        <shadow type="math_number">
          <field name="NUM">9</field>
        </shadow>
      </value>
    </block>
    <block type="math_trig">
      <value name="NUM">
        <shadow type="math_number">
          <field name="NUM">45</field>
        </shadow>
      </value>
    </block>
    <block type="math_constant"></block>
    <block type="math_number_property">
      <value name="NUMBER_TO_CHECK">
        <shadow type="math_number">
          <field name="NUM">0</field>
        </shadow>
      </value>
    </block>
    <block type="math_change">
      <value name="DELTA">
        <shadow type="math_number">
          <field name="NUM">1</field>
        </shadow>
      </value>
    </block>
    <block type="math_round">
      <value name="NUM">
        <shadow type="math_number">
          <field name="NUM">3.1</field>
        </shadow>
      </value>
    </block>
    <block type="math_on_list"></block>
    <block type="math_modulo">
      <value name="DIVIDEND">
        <shadow type="math_number">
          <field name="NUM">64</field>
        </shadow>
      </value>
      <value name="DIVISOR">
        <shadow type="math_number">
          <field name="NUM">10</field>
        </shadow>
      </value>
    </block>
    <block type="math_constrain">
      <value name="VALUE">
        <shadow type="math_number">
          <field name="NUM">50</field>
        </shadow>
      </value>
      <value name="LOW">
        <shadow type="math_number">
          <field name="NUM">1</field>
        </shadow>
      </value>
      <value name="HIGH">
        <shadow type="math_number">
          <field name="NUM">100</field>
        </shadow>
      </value>
    </block>
    <block type="math_random_int">
      <value name="FROM">
        <shadow type="math_number">
          <field name="NUM">1</field>
        </shadow>
      </value>
      <value name="TO">
        <shadow type="math_number">
          <field name="NUM">100</field>
        </shadow>
      </value>
    </block>
    <block type="math_random_float"></block>
  </category>

  <category name="{msg desc="Text Blocks"}Text{/msg}" colour="160">
    <block type="text"></block>
    <block type="text_join"></block>
    <block type="text_append">
      <value name="TEXT">
        <shadow type="text"></shadow>
      </value>
    </block>
    <block type="text_length">
      <value name="VALUE">
        <shadow type="text">
          <field name="TEXT">abc</field>
        </shadow>
      </value>
    </block>
    <block type="text_isEmpty">
      <value name="VALUE">
        <shadow type="text">
          <field name="TEXT"></field>
        </shadow>
      </value>
    </block>
    <block type="text_indexOf">
      <value name="VALUE">
        <block type="variables_get">
          <field name="VAR">text</field>
        </block>
      </value>
      <value name="FIND">
        <shadow type="text">
          <field name="TEXT">abc</field>
        </shadow>
      </value>
    </block>
    <block type="text_charAt">
      <value name="VALUE">
        <block type="variables_get">
          <field name="VAR">text</field>
        </block>
      </value>
    </block>
    <block type="text_getSubstring">
      <value name="STRING">
        <block type="variables_get">
          <field name="VAR">text</field>
        </block>
      </value>
    </block>
    <block type="text_changeCase">
      <value name="TEXT">
        <shadow type="text">
          <field name="TEXT">abc</field>
        </shadow>
      </value>
    </block>
    <block type="text_trim">
      <value name="TEXT">
        <shadow type="text">
          <field name="TEXT">abc</field>
        </shadow>
      </value>
    </block>
  </category>

  <category name="@@BLOCKS__LISTS" colour="260">

    <block type="variables_set">
      <field name="VAR">list</field>
      <value name="VALUE">
        <block type="lists_create_with">
          <mutation items="3"></mutation>
          <value name="ADD0">
            <block type="text">
              <field name="TEXT"></field>
            </block>
          </value>
          <value name="ADD1">
            <block type="text">
              <field name="TEXT"></field>
            </block>
          </value>
          <value name="ADD2">
            <block type="text">
              <field name="TEXT"></field>
            </block>
          </value>
        </block>
      </value>
    </block>

    <block type="lists_create_with">
      <mutation items="0"></mutation>
    </block>
    <block type="lists_create_with"></block>
    <block type="lists_repeat">
      <value name="NUM">
        <shadow type="math_number">
          <field name="NUM">5</field>
        </shadow>
      </value>
    </block>
    <block type="lists_length"></block>
    <block type="lists_isEmpty"></block>
    <block type="lists_indexOf">
      <value name="VALUE">
        <block type="variables_get">
          <field name="VAR">list</field>
        </block>
      </value>
    </block>
    <block type="lists_getIndex">
      <value name="VALUE">
        <block type="variables_get">
          <field name="VAR">list</field>
        </block>
      </value>
    </block>
    <block type="lists_setIndex">
      <value name="LIST">
        <block type="variables_get">
          <field name="VAR">list</field>
        </block>
      </value>
    </block>
    <block type="lists_getSublist">
      <value name="LIST">
        <block type="variables_get">
          <field name="VAR">list</field>
        </block>
      </value>
    </block>
    <block type="lists_split">
      <value name="DELIM">
        <shadow type="text">
          <field name="TEXT">,</field>
        </shadow>
      </value>
    </block>
    <block type="lists_sort"></block>
  </category>

{/template}


/**
 * Blockly default color blocks.
 */
{template .defaultColorBlocks_ private="true"}
  <category name="{msg desc="Colour Blocks"}Colour{/msg}" colour="20">
    <block type="colour_picker"></block>
    <block type="colour_random"></block>
    <block type="colour_rgb">
      <value name="RED">
        <shadow type="math_number">
          <field name="NUM">100</field>
        </shadow>
      </value>
      <value name="GREEN">
        <shadow type="math_number">
          <field name="NUM">50</field>
        </shadow>
      </value>
      <value name="BLUE">
        <shadow type="math_number">
          <field name="NUM">0</field>
        </shadow>
      </value>
    </block>
    <block type="colour_blend">
      <value name="COLOUR1">
        <shadow type="colour_picker">
          <field name="COLOUR">#ff0000</field>
        </shadow>
      </value>
      <value name="COLOUR2">
        <shadow type="colour_picker">
          <field name="COLOUR">#3333ff</field>
        </shadow>
      </value>
      <value name="RATIO">
        <shadow type="math_number">
          <field name="NUM">0.5</field>
        </shadow>
      </value>
    </block>
  </category>
{/template}
